import axios from "axios";

const getImgBlob = async function (filePath, fileName) {
  return await axios.post(`${window.config.BASE_API}/common/imgBlob`, {filePath, fileName}, {
    responseType: 'blob',
    headers: {token: localStorage.getItem('token'), 'Content-Type': 'application/json'}
  }).then(response => {
    const blob = new Blob([response.data], {type: 'application/octet-stream'});
    return window.URL.createObjectURL(blob);
  }).catch(error => {
    console.log(error)
    return null;
  })
};

const defaultPass = 'fz_123456';
const loginReg = {
  exp: new RegExp(/^[\da-zA-Z`~!@#$%^&*()._\-+=]{6,16}$/),
  msg: '请输入6到16位，包含数字、字母或以下符号：~!@#$%^&*()._-+=的账号'
}
const passReg = {
  exp: new RegExp(/^[a-zA-Z]+[a-zA-Z\d]*[`~!@#$%^&*()._\-+=]+[\da-zA-Z`~!@#$%^&*()._\-+=]*$/),
  msg: '请以英文字母开头，可以包含英文字母，数字且必须包含一位特殊符号`~!@#$%^&*()._-+='
}
const phoneNoReg = {
  exp: new RegExp(/^[\d-]{6,13}$/),
  msg: '请输入正确的电话号码'
}

export {getImgBlob, defaultPass, loginReg, passReg, phoneNoReg};